package com.corpgovernment.organization.controller;

import com.corpgovernment.api.permission.vo.AddOrUpdateMenuItemRequest;
import com.corpgovernment.api.permission.vo.DeleteMenuRequest;
import com.corpgovernment.api.permission.vo.FullMenuTo;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.permission.entity.db.Menu;
import com.corpgovernment.permission.service.UserService;
import com.corpgovernment.permission.vo.GetMenuByKeyRequest;
import com.ctrip.corp.obt.generic.utils.JsonUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zl.cui
 * @date 2022/9/7
 */
@RestController
@RequestMapping("/menu")
@Slf4j
public class MenuController {
    @Autowired
    private UserService userService;

    @PostMapping("/getMenuByKey")
    public JSONResult<Menu> getMenuByKey(@RequestBody GetMenuByKeyRequest request) {
        return JSONResult.success(userService.getMenuByKey(request.getUrl()));
    }

//
//    /**
//     * 获取全部菜单模块（树状结构）
//     * url: /corpApi/organization/menu/getAllMenuTree
//     */
//    @PostMapping("/getAllMenuTree")
//    public JSONResult<List<FullMenuTo>> getAllModuleTree() {
//        List<FullMenuTo> allUserMenu = userService.getWholeMenuTree();
//        return JSONResult.success(allUserMenu);
//    }
//
//    @PostMapping("/addOrUpdateMenu")
//    public JSONResult<String> addOrUpdateUserMenu(@RequestBody AddOrUpdateMenuItemRequest request) {
//        log.info("addOrUpdateMenu:{}", JsonUtils.toJsonString(request));
//       userService.addOrUpdateMenuItem(request.getNeedAddOrUpdateMenu());
//      return JSONResult.ok();
//    }
//
//    @PostMapping("/deleteMenu")
//    public JSONResult<String> delete(@RequestBody DeleteMenuRequest request) {
//        log.info("deleteMenu:{}", JsonUtils.toJsonString(request));
//        if (request.getNeedDeleteMenuId() == null){
//            // todo 返回码是否需要变动
//            return JSONResult.errorMsg("menu id cannot be null");
//        }
//        try {
//            userService.deleteMenuItem(request.getNeedDeleteMenuId());
//            return JSONResult.ok();
//        } catch (Exception e){
//            return JSONResult.errorException(e.getMessage());
//        }
//
//    }

}
